#include "window_message.h"
#include "lvgl.h"
#include "window_image.h"
#include "language.h"
#include "window_manager.h"


static  lv_obj_t* list1=NULL;


static void my_event_cb(lv_event_t * event)
{
	
	printf("LV_EVENT_LONG_PRESSED\r\n");
	#if 1
	lv_dir_t  dir = lv_indev_get_gesture_dir(lv_indev_get_act());//获得手势的方向
	
		//判断当前的对象
	  lv_obj_t * obj = lv_event_get_target(event);
	
	  lv_indev_t * indev = lv_indev_get_act(); //获取当前的坐标
    if(indev == NULL)  return;
	if(LV_DIR_RIGHT  == dir)  
	{
		lv_obj_del(obj);  //删除当前对象
		printf("LV_DIR_RIGHT\r\n");
		
		//设置当前的显示主界面为设置界面
	 //window_add_init();	
		
	}else if(LV_DIR_LEFT  == dir)
	{
		
		
	  printf("LV_DIR_LEFT\r\n");
	}
	
  #endif
	
}	



static void event_handler(lv_event_t * e)
{
    lv_event_code_t code = lv_event_get_code(e);
    lv_obj_t * obj = lv_event_get_target(e);
    if(code == LV_EVENT_CLICKED) {
        printf("Clicked: %s", lv_list_get_btn_text(list1, obj));
			
		  const char * txt = lv_list_get_btn_text(list1, obj);//获取当前的文本
			if((strcmp(txt, "QQ") == 0) )        //关于界面
        {
             //window_about_init();
        }else if( (strcmp(txt, "Wechat") == 0)  )//关机弹窗界面
        {
            //is_ShutDown_Menu();
        }else  if((strcmp(txt, "Message") == 0)) //显示二维码界面
        {
           //QRcode_init();
        }else  if((strcmp(txt, "Twitter") == 0))		//显示主界面
        {		
					//设置当前的显示主界面
					//lv_obj_set_tile_id(title_main,window_manger[WINDOW_MAIN].col_id, window_manger[WINDOW_MAIN].row_id,LV_ANIM_OFF);
        }else  if((strcmp(txt, "Message") == 0))//显示信息界面
        {		
					//window_message_init();
        }
    }
		

		
}



void window_message_init()
{
	 //printf("%s\r\n",__FUNCTION__);
	
	#if 1
   lv_obj_t* obj =lv_obj_create(lv_scr_act());	  //创建屏幕对象
	 lv_obj_set_style_bg_color(obj, lv_color_make(0,0,0), 0);//设置背景颜色为黑色
	 lv_obj_set_size(obj, LV_HOR_RES_MAX, LV_VER_RES_MAX);
	
	  static lv_style_t lv_style1;              //外部样式
    lv_style_init(&lv_style1);           // 初始化按钮样式
	  //lv_style_set_radius(&lv_style, 20); // 设置样式圆角弧度
	  //lv_obj_set_style_bg_color(list1, lv_color_make(0,0,0), 0);//设置背景颜色为黑色
	  lv_obj_set_scrollbar_mode(obj, LV_SCROLLBAR_MODE_OFF);  //取消滚动条显示
    //lv_obj_set_style_bg_opa(list1,LV_OPA_60,0);               //设置透明度
		lv_style_set_bg_color(&lv_style1,lv_color_make(0,0,0));
	  lv_style_set_text_align(&lv_style1,LV_TEXT_ALIGN_LEFT);
		
		lv_style_set_text_color(&lv_style1,lv_color_make(0xff,0xff,0xff));
		lv_style_set_text_color_filtered(&lv_style1,lv_color_make(0xff,0,0));
	  lv_style_set_pad_all(&lv_style1,0); //铺满整个布局
  	lv_style_set_border_color(&lv_style1,lv_color_make(0,0,0)); //设置边框颜色
	  lv_obj_add_style(obj, &lv_style1, 0);

	
	
		  
		/*Create a list*/
    list1 = lv_list_create(obj);
    lv_obj_set_size(list1, LV_HOR_RES_MAX - 20, LV_VER_RES_MAX -5);

	  //lv_obj_set_style_bg_color(list1, lv_color_make(0,0,0), 0);//设置背景颜色为黑色


	  static lv_style_t lv_style;              //外部样式
    lv_style_init(&lv_style);           // 初始化按钮样式
	  //lv_style_set_radius(&lv_style, 20); // 设置样式圆角弧度
	  //lv_obj_set_style_bg_color(list1, lv_color_make(0,0,0), 0);//设置背景颜色为黑色
	  lv_obj_set_scrollbar_mode(list1, LV_SCROLLBAR_MODE_OFF);  //取消滚动条显示
    //lv_obj_set_style_bg_opa(list1,LV_OPA_60,0);               //设置透明度
		lv_style_set_bg_color(&lv_style,lv_color_make(0,0,0));
	  lv_style_set_text_align(&lv_style,LV_TEXT_ALIGN_LEFT);
		
		lv_style_set_text_color(&lv_style,lv_color_make(0xff,0xff,0xff));
		lv_style_set_text_color_filtered(&lv_style,lv_color_make(0xff,0,0));
	  lv_style_set_pad_all(&lv_style,0); //铺满整个布局
  	lv_style_set_border_color(&lv_style,lv_color_make(0,0,0)); //设置边框颜色
    /*Add buttons to the list*/
		lv_obj_t * btn;
		btn = lv_list_add_btn(list1, (const char *)&msg_qq, "QQ");
		 lv_obj_add_event_cb(btn, event_handler, LV_EVENT_CLICKED, NULL);
		btn = lv_list_add_btn(list1, (const char *)&msg_wechat, "Wechat");
		 lv_obj_add_event_cb(btn, event_handler, LV_EVENT_CLICKED, NULL);
		btn = lv_list_add_btn(list1, (const char *)&msg_message, "Message");
		 lv_obj_add_event_cb(btn, event_handler, LV_EVENT_CLICKED, NULL);
//		btn = lv_list_add_btn(list1, (const char *)&msg_twitter, "Twitter");
//		 lv_obj_add_event_cb(btn, event_handler, LV_EVENT_CLICKED, NULL);
	
    lv_obj_add_style(list1, &lv_style, 0);
    lv_obj_center(list1);

		lv_obj_add_flag(list1,LV_OBJ_FLAG_CLICKABLE ); //增加可以长按的属性
		lv_obj_add_flag(list1,LV_OBJ_FLAG_GESTURE_BUBBLE ); //增加可以长按的属性
		
		lv_obj_add_state(list1,LV_STATE_PRESSED);

	uint32_t child_cnt = lv_obj_get_child_cnt(list1);  //获取当前的对象个数
	//printf("child_cnt=%d\r\n",child_cnt);
	lv_obj_add_event_cb(list1,my_event_cb,LV_EVENT_PRESSING,NULL);   //添加对象回调函数
	//lv_obj_add_event_cb(list1,my_event_cb,LV_EVENT_PRESSING,NULL);   //添加对象回调函数
	 
	#endif
	 
	 
	
	
}